﻿namespace AnyOffice.WebControls
{
    using System;
    using System.ComponentModel;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    [DefaultProperty("Text"), ToolboxData("<{0}:HFButton runat=server></{0}:HFButton>")]
    public class HFButton : Button
    {
        private MsgShowFlag _MsgShowFlag = MsgShowFlag.False;
        private string strAlertMessage = "";

        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);
            if (this._MsgShowFlag == MsgShowFlag.True)
            {
                string str = "javascript:return confirm('" + this.AlertMessage.Trim() + "');";
                writer.AddAttribute("onclick", str);
            }
        }

        private void MsgValidate()
        {
            if (this._MsgShowFlag == MsgShowFlag.True)
            {
                if (this.strAlertMessage.Trim() == null)
                {
                    this.strAlertMessage = "确实需要删除吗?";
                }
            }
            else
            {
                this.strAlertMessage = null;
            }
        }

        [Description("警告信息"), Browsable(true), DefaultValue("确实需要删除吗?"), Bindable(true), Category("HFClient")]
        public string AlertMessage
        {
            get
            {
                return this.strAlertMessage;
            }
            set
            {
                this.strAlertMessage = value;
            }
        }

        [Browsable(true), Description("是否需要在客户端OnClick事件中显示警告信息"), Bindable(true), Category("HFClient"), DefaultValue("否")]
        public MsgShowFlag MsgShowed
        {
            get
            {
                return this._MsgShowFlag;
            }
            set
            {
                this._MsgShowFlag = value;
                this.MsgValidate();
            }
        }

        public enum MsgShowFlag
        {
            False,
            True
        }
    }
}

